#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N=100010;

struct Ice
{
    int a;
    long long su    m;
}ice[N];
    
bool cmpsum(Ice q,Ice p)
{
    if(q.sum*p.a < p.sum*q.a) return true;
    else return false;
}

int main()
{
    int n;
    cin>>n;
    long long m=0;
    for(int i=0;i<n;i++)
    {
        int a,sum;
        cin>>a>>sum;
        ice[i].a=a;
        ice[i].sum=sum;
    }
    
    sort(ice,ice+n,cmpsum);
    
    for(int i=0;i<n;i++)
    {
        m+=ice[i].sum;
        ice[i].sum=m;
    }
     for(int i=0;i<n;i++)
    {
        cout<<ice[i].a<<" "<<ice[i].sum<<endl;
        printf("\n");
    }
    long long res=0;
    
    for(int i=n-1;i>=1;i--)
    {
        res+=ice[i].a*ice[i-1].sum;
    }
    
    cout<<res<<endl;
    
    return 0;
}
